<template>
    <div class="components-container">
        <!-- 申请 -->
        <sweet-modal ref="dialog" class="dialog" :sweetModalMaxWidth="1050">
            <h3>{{title}} </h3>
            <!-- 申请类型********************************************************************************* -->
            <fieldset class="layui-elem-field layui-field-title">
            <legend>申请类型</legend>
            <div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">申请类型</label>
                        <div class="layui-input-inline">
                            <el-select v-model="ApplicationType" placeholder="请选择申请类型" style="width:100%" @change="typechange($event)" :disabled="ischanges">
                                <el-option v-for="item in ApplicationTypedata" :key="item.value" :label="item.text" :value="item.value">
                                </el-option>
                            </el-select>
                        </div>
                    </div>
                </div>
            </div>
            </fieldset>
            <!-- 请假***************************************************************************** -->
            <fieldset class="layui-elem-field layui-field-title" v-if="leaves">
            <legend>请假信息填写</legend>
            <div class="layui-form-item">
                <div class="layui-inline" style="margin-right:15px;">
                    <label class="layui-form-label">员工姓名</label>
                    <div class="layui-input-inline" style="width:200px;">
                        <el-input v-model="ODYAPPLYMAN" readonly></el-input>
                    </div>
                </div>
                <div class="layui-inline" style="margin-right:25px;">
                    <label class="layui-form-label">所属科室</label>
                    <div class="layui-input-inline">
                        <el-input v-model="ODYDPTID" readonly></el-input>
                    </div>
                </div>
                <div class="layui-inline" style="margin:0;">
                    <label class="layui-form-label">请假事由</label>
                    <div class="layui-input-inline">
                        <el-select v-model="leavedata.ODYTYPE" placeholder="请选择请假事由" style="width:100%" :disabled="ischange">
                            <el-option v-for="item in qingjiadata" :key="item.value" :label="item.text" :value="item.value" readonly="true">
                            </el-option>
                        </el-select>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">申请日期</label>
                    <div class="layui-input-inline">
                        <el-date-picker v-date v-model="leavedata.ODYAPPLYDATE" type="datetime" placeholder="选择时间" style="width:200px;" :disabled="ischange"></el-date-picker>
                    </div>
                    <span style="width:15px;line-height:40px;">
                        <el-tooltip class="item" effect="dark" content="此日期为提交申请的日期" placement="top">
                            <i class="el-icon-question"></i>
                        </el-tooltip>
                    </span>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">请假日期</label>
                    <div class="layui-input-inline">
                        <el-date-picker v-date v-model="leavedata.ODYSTARTDATE" type="date" placeholder="选择时间" :disabled="ischange"></el-date-picker>
                    </div>
                    <span style="width:15px;line-height:40px;">
                        <el-tooltip class="item" effect="dark" content="此时间为假期开始时间" placement="top">
                            <i class="el-icon-question"></i>
                        </el-tooltip>
                    </span>
                </div>
                <div class="layui-inline" style="margin:0;">
                    <label class="layui-form-label">请假天数</label>
                    <div class="layui-input-inline">
                        <el-input v-model="leavedata.ODYDAYNUM" :disabled="ischange"></el-input>
                    </div>
                </div>
            </div>
            </fieldset>
            <!-- 调休************************************************************************************ -->
            <fieldset class="layui-elem-field layui-field-title" v-if="breakoffs">
            <legend>调休信息填写</legend>
            <div class="layui-form-item">
                <div class="layui-inline" style="margin-right:30px;">
                    <label class="layui-form-label">员工姓名</label>
                    <div class="layui-input-inline">
                        <el-input v-model="ODYAPPLYMAN" readonly style="width:200px;"></el-input>
                    </div>
                </div>
                <div class="layui-inline" style="margin-right:25px;">
                    <label class="layui-form-label">所属科室</label>
                    <div class="layui-input-inline">
                        <el-input v-model="ODYDPTID" readonly></el-input>
                    </div>
                </div>
                <div class="layui-inline" style="margin:0;">
                    <label class="layui-form-label">替班人员</label>
                    <div class="layui-input-inline">
                        <el-select v-model="breakoffdata.ODYRELAYMAN" placeholder="请选择替班人员" style="width:100%" :disabled="ischange">
                            <el-option v-for="item in allstaff" :key="item.value" :label="item.text" :value="item.value">
                            </el-option>
                        </el-select>
                    </div>
                </div>
                <!-- <div class="layui-inline">
                    <label class="layui-form-label">请假事由</label>
                    <div class="layui-input-inline">
                        <el-input v-model="breakoffdata.CRHENDOIL"></el-input>
                    </div>
                </div> -->
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">申请日期</label>
                    <div class="layui-input-inline" style="width:195px;">
                        <el-date-picker v-date v-model="breakoffdata.ODYAPPLYDATE" type="datetime" placeholder="选择时间" style="width:200px;" :disabled="ischange"></el-date-picker>
                    </div>
                    <span style="width:15px;line-height:40px;">
                        <el-tooltip class="item" effect="dark" content="此日期为提交申请的日期" placement="top">
                            <i class="el-icon-question"></i>
                        </el-tooltip>
                    </span>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">调休日期</label>
                    <div class="layui-input-inline">
                        <el-date-picker v-date v-model="breakoffdata.ODYSTARTDATE" type="date" placeholder="选择时间" :disabled="ischange"></el-date-picker>
                    </div>
                    <span style="width:15px;line-height:40px;">
                        <el-tooltip class="item" effect="dark" content="此时间为调休开始时间" placement="top">
                            <i class="el-icon-question"></i>
                        </el-tooltip>
                    </span>
                </div>
                <div class="layui-inline" style="margin:0;">
                    <label class="layui-form-label">调休天数</label>
                    <div class="layui-input-inline">
                        <el-input v-model="breakoffdata.ODYDAYNUM" :disabled="ischange"></el-input>
                    </div>
                </div>
            </div>
            </fieldset>
            <!-- 出差**************************************************************************** -->
            <fieldset class="layui-elem-field layui-field-title" v-if="business">
            <legend>出差信息填写</legend>
             <div class="layui-form-item">
                <div class="layui-inline" style="margin-right:30px;">
                    <label class="layui-form-label">员工姓名</label>
                    <div class="layui-input-inline">
                        <el-input v-model="ODYAPPLYMAN" readonly style="width:200px;"></el-input>
                    </div>
                </div>
                <div class="layui-inline" style="margin-right:25px;">
                    <label class="layui-form-label">所属科室</label>
                    <div class="layui-input-inline">
                        <el-input v-model="ODYDPTID" readonly></el-input>
                    </div>
                </div>
                <div class="layui-inline" style="margin:0;">
                    <label class="layui-form-label">出差地点</label>
                    <div class="layui-input-inline">
                        <el-input v-model="bussinessdata.ODYADRESS"></el-input>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">申请日期</label>
                    <div class="layui-input-inline" style="width:195px;">
                        <el-date-picker v-date v-model="bussinessdata.ODYAPPLYDATE" type="datetime" placeholder="选择时间" style="width:200px;" :disabled="ischange"></el-date-picker>
                    </div>
                    <span style="width:15px;line-height:40px;">
                        <el-tooltip class="item" effect="dark" content="此日期为提交申请的日期" placement="top">
                            <i class="el-icon-question"></i>
                        </el-tooltip>
                    </span>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">出差时间</label>
                    <div class="layui-input-inline">
                        <el-date-picker v-date v-model="bussinessdata.ODYSTARTDATE" type="date" placeholder="选择时间" :disabled="ischange"></el-date-picker>
                    </div>
                    <span style="width:15px;line-height:40px;">
                        <el-tooltip class="item" effect="dark" content="此时间为出差开始时间" placement="top">
                            <i class="el-icon-question"></i>
                        </el-tooltip>
                    </span>
                </div>
                <div class="layui-inline" style="margin:0;">
                    <label class="layui-form-label">出差天数</label>
                    <div class="layui-input-inline">
                        <el-input v-model="bussinessdata.ODYDAYNUM" :disabled="ischange"></el-input>
                    </div>
                </div>
            </div>
           
            </fieldset>
            <!-- 活动********************************************************************************** -->
            <fieldset class="layui-elem-field layui-field-title" v-if="activitys">
            <legend>活动信息填写</legend>
            <div class="layui-form-item">
                <div class="layui-inline" style="margin-right:30px;">
                    <label class="layui-form-label">员工姓名</label>
                    <div class="layui-input-inline">
                        <el-input v-model="ODYAPPLYMAN" readonly style="width:200px;"></el-input>
                    </div>
                </div>
                <div class="layui-inline" style="margin-right:25px;">
                    <label class="layui-form-label">所属科室</label>
                    <div class="layui-input-inline">
                        <el-input v-model="ODYDPTID" readonly></el-input>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">培训机构</label>
                    <div class="layui-input-inline">
                        <el-input v-model="activity.ODYTRAINORGIN" :disabled="ischange"></el-input>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                 <div class="layui-inline">
                    <label class="layui-form-label">申请日期</label>
                    <div class="layui-input-inline" style="width:195px;">
                        <el-date-picker v-date v-model="activity.ODYAPPLYDATE" type="datetime" placeholder="选择时间" style="width:200px;" :disabled="ischange"></el-date-picker>
                    </div>
                    <span style="width:15px;line-height:40px;">
                        <el-tooltip class="item" effect="dark" content="此日期为提交申请的日期" placement="top">
                            <i class="el-icon-question"></i>
                        </el-tooltip>
                    </span>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">培训时间</label>
                    <div class="layui-input-inline">
                        <el-date-picker v-date v-model="activity.ODYSTARTDATE" type="date" placeholder="选择时间" :disabled="ischange"></el-date-picker>
                    </div>
                    <span style="width:15px;line-height:40px;">
                        <el-tooltip class="item" effect="dark" content="此时间为培训开始时间" placement="top">
                            <i class="el-icon-question"></i>
                        </el-tooltip>
                    </span>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">培训天数</label>
                    <div class="layui-input-inline">
                        <el-input v-model="activity.ODYDAYNUM" :disabled="ischange"></el-input>
                    </div>
                </div>
            </div>
             <div class="layui-form-item">
                <div class="layui-inline" style="margin-right:30px;">
                    <label class="layui-form-label">培训预算</label>
                    <div class="layui-input-inline">
                        <el-input v-model="activity.ODYTRAINBUDGET" style="width:200px;" :disabled="ischange"></el-input>
                    </div>
                </div>
                <div class="layui-inline" style="margin-right:25px;">
                    <label class="layui-form-label">培训目的</label>
                    <div class="layui-input-inline">
                        <el-input v-model="activity.ODYTRAINAIM" :disabled="ischange"></el-input>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">培训地点</label>
                    <div class="layui-input-inline">
                        <el-input v-model="activity.ODYADRESS" :disabled="ischange"></el-input>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">培训内容</label>
                    <div class="layui-input-inline">
                        <el-input type="textarea" style="width:830px;" v-model="activity.ODYCONTENT" :disabled="ischange"></el-input>
                    </div>
                </div>
            </div>
           
            </fieldset>
            <div class="layui-form-item btnCenter">
                <el-button @click="cancel">取消</el-button>
                <el-button type="primary" :loading="loading" @click="tijao" v-if="isshowtijiao">提交</el-button>
                <el-button type="primary" :loading="loading" @click="submit" v-if="!ischange">保存</el-button>
                <el-button type="primary" :loading="loading" @click="forwards" v-if="isshowbutton">{{forward}}</el-button>
                <el-button type="primary" :loading="loading" @click="backs" v-if="isshowbuttons">{{back}}</el-button>
            </div>
        </sweet-modal>
    </div>
</template>

<style rel="stylesheet/scss" lang="scss" scoped>

</style>
<script>
    import sweetModal from "@/components/sweetModal";
    import apiBase from "@/api/apiBase.js";
    import {
        formatDate,
        timeStringToDate,
        dateStringToDate
    } from "@/utils/date.js";
    import {
        manage
    } from "@/mixins/managePage.js";
    const APPLY = "申请";
    const MODIFY = "修改";
    const DELETE = "删除";
    const INFO = "详情";
    const BEG = "开始使用";
    const END = "结束使用";
    export default {
        name: "creUseMain",
        mixins: [manage],
        props: ['isUse'],
        data() {
            return {
                ApplicationType: 'A', //申请类型
                ApplicationTypedata: [], //申请类型数据
                leaves: false,//控制请假信息的显隐
                breakoffs: false,//控制调休信息的显隐
                business: false,//控制出差信息的显隐
                activitys: false,//控制活动信息的显隐
                qingjiadata: [],//请假中的请假事由
                leavedata: {
                    ODYSTARTDATE: null,
                    ODYTYPE: null,
                    ODYAPPLYDATE: null,
                },//请假字段集合点
                breakoffdata: {
                    ODYRELAYMAN: null,
                    ODYSTARTDATE: null,
                    ODYTYPE: null,
                    ODYAPPLYDATE: null,
                },//调休字段集合点
                bussinessdata: {
                    ODYADRESS: null,
                    ODYSTARTDATE: null,
                    ODYTYPE: null,
                    ODYAPPLYDATE: null,
                },//出差字段集合点
                activity: {
                    ODYSTARTDATE: null,
                    ODYTYPE: null,
                    ODYAPPLYDATE: null,
                    ODYTRAINORGIN: null,
                    ODYTRAINBUDGET: null,
                    ODYTRAINAIM: null,
                    ODYADRESS: null,
                },//活动字段集合点
                ODYAPPLYMAN: null,//员工姓名
                ODYDPTID: null,//所属科室
                allstaff: [],//所有员工
                ischange: false,
                ischanges: false,
                ids: null,
                forward: null,//下一步按钮
                back: null,//上一步按钮
                isshowbutton: false,
                isshowbuttons: false,
                isshowtijiao: false,
            }
        },
        methods: {
            //获取各种数据的集合点
            getalldata(){
                this.GetOdyType(); //获取考勤类型
                this.GetSJ(); // 获取事假明细
                this.getbmname(); //获取所属部门
                this.getallstaff();//获取所有的员工
                //获取姓名
                var username = localStorage.getItem('username');
                this.ODYAPPLYMAN = username;
            },
            open(order, id) {
                this.order = order;
                this.ids = id;
                this.getalldata();
                this.dataRepeat();
                this.ischange = false;
                this.ischanges = false;
                this.isshowbutton = false;
                this.isshowbuttons = false;
                this.isshowtijiao = false;
                switch (this.order) {
                    case MODIFY:
                        this.title = "请假修改";
                        this.dataInfo(id);
                        this.ischange = false;
                        this.ischanges = true;
                        this.$refs.dialog.open();
                        break;
                    case INFO:
                        this.title = "请假详情";
                        this.dataInfo(id);
                        this.ischange = true;
                        this.ischanges = true;
                        this.$refs.dialog.open();
                        break;
                    case APPLY:
                        this.title = "请假申请";
                        this.ApplicationType = 'A';
                        this.leaves = true;//默认是请假信息
                        this.breakoffs = false;
                        this.business = false;
                        this.activitys = false;
                        this.isshowtijiao = true;
                        this.$refs.dialog.open();
                        break;
                    case '提交':
                        this.title = "提交";
                        this.dataInfo(id);
                        this.ischange = true;
                        this.ischanges = true;
                        this.isshowbutton = true;
                        this.forward = '确认提交';
                        this.back = '取消提交';
                        this.$refs.dialog.open();
                        break;
                    case '初审':
                        this.title = "初审";
                        this.dataInfo(id);
                        this.ischange = true;
                        this.ischanges = true;
                        this.isshowbutton = true;
                        this.isshowbuttons = true;
                        this.forward = '通过初审';
                        this.back = '取消初审';
                        this.$refs.dialog.open();
                        break;
                    case '复审':
                        this.title = "复审";
                        this.dataInfo(id);
                        this.ischange = true;
                        this.ischanges = true;
                        this.isshowbutton = true;
                        this.isshowbuttons = true;
                        this.forward = '通过复审';
                        this.back = '取消复审';
                        this.$refs.dialog.open();
                        break;
                    case '审批':
                        this.title = "审批";
                        this.dataInfo(id);
                        this.ischange = true;
                        this.ischanges = true;
                        this.isshowbutton = true;
                        this.isshowbuttons = true;
                        this.forward = '通过审批';
                        this.back = '取消审批';
                        this.$refs.dialog.open();
                        break;
                    default:
                }
            },
           tijao(){
               let Data;
                var times;
                if(this.ApplicationType === "A"){
                    Data = JSON.parse(JSON.stringify(this.leavedata));
                    times = this.leavedata.ODYSTARTDATE
                }else if(this.ApplicationType === 'B'){
                    Data = JSON.parse(JSON.stringify(this.breakoffdata));
                    Data.ODYTYPE = '调休';
                    times = this.breakoffdata.ODYSTARTDATE
                }else if(this.ApplicationType === 'C'){
                    Data = JSON.parse(JSON.stringify(this.bussinessdata));
                    Data.ODYTYPE = '出差';
                    times = this.bussinessdata.ODYSTARTDATE
                }else if(this.ApplicationType === 'D'){
                    Data = JSON.parse(JSON.stringify(this.activity));
                    Data.ODYTYPE = '活动';
                    times = this.activity.ODYSTARTDATE
                }
                //假期开始日期
                if(Data.ODYSTARTDATE){
                    Data.ODYSTARTDATE =  formatDate(Data.ODYSTARTDATE, "yyyyMMdd");
                }
                //请假申请日期
                if(Data.ODYAPPLYDATE){ 
                    Data.ODYAPPLYTIME = formatDate(Data.ODYAPPLYDATE, "hhmmss");
                    Data.ODYAPPLYDATE = formatDate(Data.ODYAPPLYDATE, "yyyyMMdd");
                }
                //假期结束时间
                if(Data.ODYDAYNUM){
                    var num = Number(Data.ODYDAYNUM)
                    if(num <= 1){
                        Data.ODYENDDATE = Data.ODYSTARTDATE
                    }else{
                        var milliseconds=times.getTime()+1000*60*60*24*(parseInt(Math.round(num))-1);
                        var newDate= new Date(milliseconds);
                        Data.ODYENDDATE = formatDate(newDate, "yyyyMMdd");
                    }
                }
               apiBase.DoService(
                    Data,
                    apiBase.getApiAdress().OnDuty.Create,
                    res => {
                        this.refreshData();
                        this.cancel();
                        this.$message({
                            type: "success",
                            message: "新增成功!"
                        });
                        this.ids = res.data.content.ODYID;
                        setTimeout(() => {
                            this.forwards();
                        }, 100);
                    },
                    res => {
                        this.$message.error(res.data.msg);
                    }
                );
           },
            // 获取考勤类型
            GetOdyType () {
                apiBase.DoService({},
                    apiBase.getApiAdress().OnDuty.GetOdyType,
                    res => {
                        let creTypeData = res.data.content,
                            legendsCreData = creTypeData.map(item => ({
                                text: item.Text,
                                value: item.Value
                            }));
                        this.ApplicationTypedata = legendsCreData;
                    }
                );
            },
            // 获取事假明细
            GetSJ() {
                apiBase.DoService({},
                    apiBase.getApiAdress().OnDuty.GetSJ,
                    res => {
                        let creTypeData = res.data.content,
                            legendsCreData = creTypeData.map(item => ({
                                text: item.Text,
                                value: item.Value
                            }));
                        this.qingjiadata = legendsCreData;
                    }
                );
            },
            //获取部门名称
            getbmname() {
                let data = {};
                apiBase.DoService(
                    data,
                    apiBase.getApiAdress().JointRegistration.GetDpeName,
                    res => {
                        var s = res.data.content.DPTNAME;
                        this.ODYDPTID = s;
                    }
                );
            },
            //获取所有的员工
            getallstaff() {
                let data = {};
                apiBase.DoService(
                    data,
                    apiBase.getApiAdress().Staff.QueryNolstaff,
                    res => {
                        let Staff = res.data.content,
                            Staffs = Staff.map(item => ({
                                text: item.STANAME,
                                value: item.STAID
                            }));
                        this.allstaff = Staffs;
                    }
                );
            },
            typechange(val){
                if(val === 'A'){
                    this.leaves = true;
                    this.breakoffs = false;
                    this.business = false;
                    this.activitys = false;
                }else if(val === 'B'){
                    this.breakoffs = true;
                    this.leaves = false;
                    this.business = false;
                    this.activitys = false;
                }else if(val === 'C'){
                    this.business = true;
                    this.leaves = false;
                    this.breakoffs = false;
                    this.activitys = false;
                }else if(val === 'D'){
                    this.activitys = true;
                    this.leaves = false;
                    this.breakoffs = false;
                    this.business = false;
                }
            },
            //提交
            submit() {
                switch (this.order) {
                    case APPLY:
                        this.dataAdd();
                        break;
                    case MODIFY:
                        this.dataModify();
                        break;
                    default:
                }
            },
           forwards(){
               let data = {
                   ODYID: this.ids
               };
                apiBase.DoService(
                    data,
                    apiBase.getApiAdress().OnDuty.Forward,
                    res => {
                        this.$message.success('成功！');
                        this.$refs.dialog.close();
                        this.refreshData();
                    }
                );
           },
           backs() {
               let data = {
                   ODYID: this.ids
               };
                apiBase.DoService(
                    data,
                    apiBase.getApiAdress().OnDuty.Back,
                    res => {
                        this.$message.success('成功！');
                        this.$refs.dialog.close();
                        this.refreshData();
                    }
                );
           },
            //新增
            dataAdd() {
                let Data;
                var times;
                if(this.ApplicationType === "A"){
                    Data = JSON.parse(JSON.stringify(this.leavedata));
                    times = this.leavedata.ODYSTARTDATE
                }else if(this.ApplicationType === 'B'){
                    Data = JSON.parse(JSON.stringify(this.breakoffdata));
                    Data.ODYTYPE = '调休';
                    times = this.breakoffdata.ODYSTARTDATE
                }else if(this.ApplicationType === 'C'){
                    Data = JSON.parse(JSON.stringify(this.bussinessdata));
                    Data.ODYTYPE = '出差';
                    times = this.bussinessdata.ODYSTARTDATE
                }else if(this.ApplicationType === 'D'){
                    Data = JSON.parse(JSON.stringify(this.activity));
                    Data.ODYTYPE = '活动';
                    times = this.activity.ODYSTARTDATE
                }
                //假期开始日期
                if(Data.ODYSTARTDATE){
                    Data.ODYSTARTDATE =  formatDate(Data.ODYSTARTDATE, "yyyyMMdd");
                }
                //请假申请日期
                if(Data.ODYAPPLYDATE){ 
                    Data.ODYAPPLYTIME = formatDate(Data.ODYAPPLYDATE, "hhmmss");
                    Data.ODYAPPLYDATE = formatDate(Data.ODYAPPLYDATE, "yyyyMMdd");
                }
                //假期结束时间
                if(Data.ODYDAYNUM){
                    var num = Number(Data.ODYDAYNUM)
                    if(num <= 1){
                        Data.ODYENDDATE = Data.ODYSTARTDATE
                    }else{
                        var milliseconds=times.getTime()+1000*60*60*24*(parseInt(Math.round(num))-1);
                        var newDate= new Date(milliseconds);
                        Data.ODYENDDATE = formatDate(newDate, "yyyyMMdd");
                    }
                }
               apiBase.DoService(
                    Data,
                    apiBase.getApiAdress().OnDuty.Create,
                    res => {
                        this.refreshData();
                        this.cancel();
                        this.$message({
                            type: "success",
                            message: "新增成功!"
                        });
                    },
                    res => {
                        this.$message.error(res.data.msg);
                    }
                );
            },
            //只能输入正整数
            checkNumber(value) {
                console.log(value);
                value = value.replace(/\D/g, "").replace(/^0+(?=\d)/, "");
                if (value !== "") {
                    if (value.substr(0, 1) === "0" && value.length === 2) {
                        value = value.substr(1, value.length);
                    }
                } else {
                    value = 0;
                }
                return value;
            },
            //详情
            dataInfo(id) {
                var data = {
                    ODYID: id
                };
                apiBase.DoService(
                    data,
                    apiBase.getApiAdress().OnDuty.Detail,
                    res => {
                        var qingjiadata = res.data.content;
                        if(qingjiadata.ODYTYPE === '调休'){
                            this.ApplicationType = 'B';
                            this.leaves = false;
                            this.breakoffs = true;
                            this.business = false;
                            this.activitys = false;
                            this.breakoffdata.ODYRELAYMAN = qingjiadata.ODYRELAYMAN;
                            this.breakoffdata.ODYAPPLYDATE = qingjiadata.ODYAPPLYDATEDESC
                            this.breakoffdata.ODYSTARTDATE = dateStringToDate(
                                qingjiadata.ODYSTARTDATE
                            );
                            this.breakoffdata.ODYDAYNUM = qingjiadata.ODYDAYNUM;
                        }else if(qingjiadata.ODYTYPE === '出差'){
                            this.ApplicationType = 'C';
                            this.leaves = false;
                            this.breakoffs = false;
                            this.business = true;
                            this.activitys = false;
                            this.bussinessdata.ODYADRESS = qingjiadata.ODYADRESS;
                            this.bussinessdata.ODYAPPLYDATE = qingjiadata.ODYAPPLYDATEDESC
                            this.bussinessdata.ODYSTARTDATE = dateStringToDate(
                                qingjiadata.ODYSTARTDATE
                            );
                            this.bussinessdata.ODYDAYNUM = qingjiadata.ODYDAYNUM;
                        }else if(qingjiadata.ODYTYPE === '活动'){
                            this.ApplicationType = 'D';
                            this.leaves = false;
                            this.breakoffs = false;
                            this.business = false;
                            this.activitys = true;
                            this.activity.ODYTRAINORGIN = qingjiadata.ODYTRAINORGIN;
                            this.activity.ODYTRAINBUDGET = qingjiadata.ODYTRAINBUDGET;
                            this.activity.ODYTRAINAIM = qingjiadata.ODYTRAINAIM;
                            this.activity.ODYADRESS = qingjiadata.ODYADRESS;
                            this.activity.ODYCONTENT = qingjiadata.ODYCONTENT;
                            this.activity.ODYAPPLYDATE = qingjiadata.ODYAPPLYDATEDESC
                            this.activity.ODYSTARTDATE = dateStringToDate(
                                qingjiadata.ODYSTARTDATE
                            );
                            this.activity.ODYDAYNUM = qingjiadata.ODYDAYNUM;
                        }else {//请假
                            this.ApplicationType = 'A';
                            this.leaves = true;
                            this.breakoffs = false;
                            this.business = false;
                            this.activitys = false;
                            this.leavedata.ODYTYPE = qingjiadata.ODYTYPE;
                            this.leavedata.ODYAPPLYDATE = qingjiadata.ODYAPPLYDATEDESC
                            this.leavedata.ODYSTARTDATE = dateStringToDate(
                                qingjiadata.ODYSTARTDATE
                            );
                            this.leavedata.ODYDAYNUM = qingjiadata.ODYDAYNUM;
                        }
                    }
                );
            },
            //修改
            dataModify() {
                let Data;
                var times;
                if(this.ApplicationType === "A"){
                    Data = JSON.parse(JSON.stringify(this.leavedata));
                    times = this.leavedata.ODYSTARTDATE
                }else if(this.ApplicationType === 'B'){
                    Data = JSON.parse(JSON.stringify(this.breakoffdata));
                    Data.ODYTYPE = '调休';
                    times = this.breakoffdata.ODYSTARTDATE
                }else if(this.ApplicationType === 'C'){
                    Data = JSON.parse(JSON.stringify(this.bussinessdata));
                    Data.ODYTYPE = '出差';
                    times = this.bussinessdata.ODYSTARTDATE
                }else if(this.ApplicationType === 'D'){
                    Data = JSON.parse(JSON.stringify(this.activity));
                    Data.ODYTYPE = '活动';
                    times = this.activity.ODYSTARTDATE
                }
                //假期开始日期
                if(Data.ODYSTARTDATE){
                    Data.ODYSTARTDATE =  formatDate(Data.ODYSTARTDATE, "yyyyMMdd");
                }
                //请假申请日期
                if(Data.ODYAPPLYDATE){ 
                    Data.ODYAPPLYTIME = formatDate(Data.ODYAPPLYDATE, "hhmmss");
                    Data.ODYAPPLYDATE = formatDate(Data.ODYAPPLYDATE, "yyyyMMdd");
                }
                //假期结束时间
                if(Data.ODYDAYNUM){
                    var num = Number(Data.ODYDAYNUM)
                    if(num <= 1){
                        Data.ODYENDDATE = Data.ODYSTARTDATE
                    }else{
                        var milliseconds=times.getTime()+1000*60*60*24*(parseInt(Math.round(num))-1);
                        var newDate= new Date(milliseconds);
                        Data.ODYENDDATE = formatDate(newDate, "yyyyMMdd");
                    }
                }
                Data.ODYID = this.ids;
                apiBase.DoService(
                    Data,
                    apiBase.getApiAdress().OnDuty.Modify,
                    res => {
                        this.$refs.dialog.close();
                        this.$message({
                            message: "修改成功！",
                            type: "success"
                        });
                        this.refreshData();
                    },
                    res => {
                        this.$message.error(res.data.msg);
                    });
            },
          
            //刷新
            refreshData() {
                this.$emit("refreshData");
            },
            //数据重置
            dataRepeat() {
                this.leavedata = {
                    ODYSTARTDATE: null,
                    ODYTYPE: null,
                    ODYAPPLYDATE: null,
                },//请假字段集合点
                this.breakoffdata = {
                    ODYRELAYMAN: null,
                    ODYSTARTDATE: null,
                    ODYTYPE: null,
                    ODYAPPLYDATE: null,
                },//调休字段集合点
                this.bussinessdata = {
                    ODYADRESS: null,
                    ODYSTARTDATE: null,
                    ODYTYPE: null,
                    ODYAPPLYDATE: null,
                },//出差字段集合点
                this.activity = {
                    ODYSTARTDATE: null,
                    ODYTYPE: null,
                    ODYAPPLYDATE: null,
                    ODYTRAINORGIN: null,
                    ODYTRAINBUDGET: null,
                    ODYTRAINAIM: null,
                    ODYADRESS: null,
                }//活动字段集合点
            },
        },
        created(){
            
        },
        computed: {
           
        },
        components: {
            sweetModal
        }
    };
</script>

